#include "dxstdafx.h"
#include ".\utilities.h"

/**
 * \brief makes a new character string from the passed one
 * \param c_str - the null terminated char string
 * \return the new string. Caller is responsible for freeing the memory
 * \author Keith Ditchburn \date 17 July 2005
*/
char* CUtilities::DuplicateCharString(const char* c_str)
{
    if (!c_str)
		return NULL;

	size_t len=strlen(c_str) + 1;
	char *newString = new char[len];
	memcpy(newString, c_str, len*sizeof(char));

	return newString;
}

/**
 * \brief takes a char string and creates a wide string from it
 * \param c_str - the null terminated char string
 * \return the new string. Called is responsible for deleting memory
 * \author Keith Ditchburn \date 17 July 2005
*/
WCHAR* CUtilities::CreateWideStringFromCharString(const char *c_str)
{
	if (!c_str)
		return NULL;

	size_t len=strlen(c_str)+1;
	WCHAR *wideString=new WCHAR[len];

	if( MultiByteToWideChar( CP_ACP, 0, c_str, -1, wideString, (int)len ) == 0 )
		return NULL;

	return wideString;
}

/**
 * \brief takes a char string and creates a wide string from it
 * \param c_str - the null terminated char string
 * \param widestring - the wide string to write to
 * \param wideStringLen - the length of the wide string
 * \return the new string. Caller is responsible for deleting memory.
 * \author Keith Ditchburn \date 17 July 2005
*/
bool CUtilities::FillWideStringFromCharString(const char *c_str,WCHAR *wideString,size_t wideStringLen)
{
	if (!c_str || !wideString)
		return false;

	if( MultiByteToWideChar( CP_ACP, 0, c_str, -1, wideString, (int)wideStringLen ) == 0 )
		return false;

	return true;
}